package team2.arsystem.GUI;

import team2.arsystem.Utilities.CommandConstants;
import team2.arsystem.GUI.R;
import team2.arsystem.Controller.ApplicationController;
import team2.arsystem.Utilities.*;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Checkable;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.Spinner;

public class LoginScreen extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        
    	super.onCreate(savedInstanceState);
        setContentView(R.layout.welcomescreen);
              
        Button loginButton = (Button)findViewById(R.id.buttonlogin);
        final EditText userNameEditText = (EditText)findViewById(R.id.editTextUsername);
        final EditText passwordEditText = (EditText)findViewById(R.id.editTextPassword);
        Button createAccountButton = (Button)findViewById(R.id.buttonCreateAccount);
        
        loginButton.setOnClickListener(new OnClickListener() {
			
        	public void onClick(View v) {
        		
        	String[] loginCredentials = new String[2];	
        	loginCredentials[0] = userNameEditText.getText().toString();
        	loginCredentials[1] = passwordEditText.getText().toString();
        	
        	if((ApplicationController.getApplicationController().passCommand(CommandConstants.loginUser,loginCredentials)))
        	{
        		try
        		{
        		 Class menuScreen = Class.forName("team2.arsystem.GUI."+"MenuScreen");
        		 Intent myIntent = new Intent(LoginScreen.this,menuScreen);
        		 startActivity(myIntent);
        		}
        		 catch(Exception e)
        		 {
        			 e.printStackTrace();
        		 }
        	}
        		
			}
		});
        
        /*End of loginButton Click handler*/
        
        createAccountButton.setOnClickListener(new OnClickListener() {
			
        	public void onClick(View v) {
        		
        		try
        		{
        		 Class createAccountScreen = Class.forName("team2.arsystem.GUI."+"CreateNewAccount");
        		 Intent myIntent = new Intent(LoginScreen.this,createAccountScreen);
        		 startActivity(myIntent);
        		}
        		catch(Exception e)
        		{
        			e.printStackTrace();
        		}
			}
		});
       
       
    }
  
  
}
